←Select platform

DecodeAbic(byte[],int,int,int,bool) Method

Summary
Decodes the input ABIC data using the ABIC decoder and returns raw uncompressed data.
Syntax
C#
C++/CLI
Java
Python
public byte[] DecodeAbic( 
   byte[] inputData, 
   int align, 
   int width, 
   int height, 
   bool biLevel 
) 
public byte[] decodeAbic(byte[] inputData, int align, int width, int height, boolean biLevel) 
public: 
array<byte>^ DecodeAbic(  
   array<byte>^ inputData, 
   int align, 
   int width, 
   int height, 
   bool biLevel 
)  
def DecodeAbic(self,inputData,align,width,height,biLevel): 

Parameters

inputData
A byte array which contains the input data.

align
Number of bytes to align the uncompressed output data.

width
Image width, in pixels.

height
Image height, in pixels.

biLevel
true to indicate bi-level encoding, false to indicate 4-bit grayscale encoding.

Return Value

A byte array that contains the raw uncompressed data.

Remarks

Call this method to decompress the input 1-bit bi-level or 4-bit grayscale ABIC data.

Use EncodeAbic to encode ABIC data.

The output buffer in the RasterNativeBuffer object returned is allocated automatically by this method. The user is responsible to free this unmanaged memory buffer by calling Marshal.FreeHGlobal as follows:

RasterNativeBuffer buffer = rasterCodecsObject.EncodeAbic(...)// Use buffer Marshal.FreeHGlobal(buffer.Data);
Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
 
public void EncodeDecodeAbic4BitExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp"); 
   string destDataFile = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Abic_4Bit.bmp"); 
 
   // Load the file save it to a memory stream as RAW 
   Debug.WriteLine("Loading the source image as 1 bits/pixel"); 
   RasterImage srcImage = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.Rgb, 1, 1); 
 
   // Convert it to 4-bit image with optimized palette using Floyd Steinberg dithering for best quality. 
   // 
   // We could also load the source image straight to 4-bits per pixel, 
   // but that operation creates a 4-bit bitmap with fixed palette and the output does not look as good. 
   ColorResolutionCommand cmdColorRes = new ColorResolutionCommand( 
      ColorResolutionCommandMode.InPlace, 
      4, 
      RasterByteOrder.Rgb, 
      RasterDitheringMethod.FloydStein, 
      ColorResolutionCommandPaletteFlags.Optimized, 
      null); 
   cmdColorRes.Run(srcImage); 
 
   Debug.WriteLine("Saving the image to memory as RAW format"); 
   MemoryStream ms = new MemoryStream(); 
   codecs.Save(srcImage, ms, RasterImageFormat.Raw, srcImage.BitsPerPixel); 
 
   Debug.WriteLine("Encoding the data as ABIC"); 
   byte[] rawData = ms.GetBuffer(); 
   ms.Close(); 
 
   // Encode this data as ABIC 
   Debug.WriteLine("Encode this data as ABIC"); 
   byte[] abicData = codecs.EncodeAbic(rawData, 1, srcImage.Width, srcImage.Height, false); 
 
   // Decode the data back to RAW 
   Debug.WriteLine("Decoding the data back as RAW"); 
   rawData = codecs.DecodeAbic(abicData, 4, srcImage.Width, srcImage.Height, false); 
 
   // Create a new image from this data 
   RasterImage destImage = new RasterImage( 
      RasterMemoryFlags.Conventional, 
      srcImage.Width, 
      srcImage.Height, 
      srcImage.BitsPerPixel, 
      srcImage.Order, 
      srcImage.ViewPerspective, 
      srcImage.GetPalette(), 
      IntPtr.Zero, 
      0); 
 
   destImage.Access(); 
 
   // Add the scan lines 
   for (int y = 0; y < destImage.Height; y++) 
   { 
      int bufferIndex = y * destImage.BytesPerLine; 
      destImage.SetRow(y, rawData, bufferIndex, destImage.BytesPerLine); 
   } 
 
   destImage.Release(); 
 
   // Save this image to disk 
   codecs.Save(destImage, destDataFile, RasterImageFormat.Bmp, destImage.BitsPerPixel); 
 
   srcImage.Dispose(); 
   destImage.Dispose(); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
public void EncodeDecodeAbic1BitExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp"); 
   string destDataFile = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Abic_1Bit.bmp"); 
 
   // Load the file save it to a memory stream as RAW  
   Console.WriteLine("Loading the source image at 1 bit/pixel"); 
   RasterImage srcImage = codecs.Load(srcFileName, 1, CodecsLoadByteOrder.Rgb, 1, 1); 
 
   Console.WriteLine("Saving the image to memory as RAW format"); 
   MemoryStream ms = new MemoryStream(); 
   codecs.Save(srcImage, ms, RasterImageFormat.Raw, srcImage.BitsPerPixel); 
 
   Console.WriteLine("Encoding the data as ABIC"); 
   byte[] rawData = ms.GetBuffer(); 
   ms.Close(); 
 
   // Encode this data as ABIC  
   byte[] abicData = codecs.EncodeAbic(rawData, 1, srcImage.Width, srcImage.Height, true); 
 
   // Decode the data back to RAW           
   Console.WriteLine("Decoding the data back as RAW"); 
   rawData = codecs.DecodeAbic(abicData, 4, srcImage.Width, srcImage.Height, true); 
 
   // Create a new image from this data  
   RasterImage destImage = new RasterImage( 
      RasterMemoryFlags.Conventional, 
      srcImage.Width, 
      srcImage.Height, 
      srcImage.BitsPerPixel, 
      srcImage.Order, 
      srcImage.ViewPerspective, 
      srcImage.GetPalette(), 
      IntPtr.Zero, 
      0); 
 
   destImage.Access(); 
 
   // Add the scan lines  
   for (int y = 0; y < destImage.Height; y++) 
   { 
      int bufferIndex = y * destImage.BytesPerLine; 
      destImage.SetRow(y, rawData, bufferIndex, destImage.BytesPerLine); 
   } 
 
   destImage.Release(); 
 
   // Save this image to disk  
   codecs.Save(destImage, destDataFile, RasterImageFormat.Bmp, destImage.BitsPerPixel); 
 
   srcImage.Dispose(); 
   destImage.Dispose(); 
 
   // Clean up  
   codecs.Dispose(); 
} 
 
 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.11.27
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.